/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_httpd.htm
 *
 * Zhiqim Httpd is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.httpd;

import java.io.IOException;

import org.zhiqim.httpd.websocket.HttpWebSocketService;
import org.zhiqim.kernel.model.maps.HashMapSS;
import org.zhiqim.kernel.logging.Log;
import org.zhiqim.kernel.logging.LogFactory;
import org.zhiqim.kernel.model.seqs.Sequence;

/**
 * HTTP连接接口定义
 *
 * @version v1.0.0 @author zouzhigang 2016-7-18 新建与整理
 */
public interface HttpConnection extends HttpdConstants
{
    public Log log = LogFactory.getLog(HttpConnection.class);
    public Sequence sequence = new Sequence(6);
    
    /********************************************************************/
    //连接中状态
    /********************************************************************/
    
    /** 是否活动 */
    public boolean isActive();
    
    /** 是否超时 */
    public boolean isOvertime();
    
    /** 是否已关闭 */
    public boolean isClosed();
    
    /********************************************************************/
    //连接中的WebSocket
    /********************************************************************/
    
    /** 是否是WebSocket连接 */
    public boolean isWebSocket();
    
    /** 升级为WebSocket连接 */
    public void doWebSocket(HttpContext context, HashMapSS headers, HashMapSS parameters, String protocol, String sessionId, HttpWebSocketService service);
    
    /** 开启WebScoket回调 */
    public void doWebSocketOpen();
    
    /********************************************************************/
    //连接中write&close
    /********************************************************************/
    
    /** 写入数据 */
    public void write(byte[] data) throws IOException;
    
    /** 写入数据 */
    public void write(byte[] data, int off, int len) throws IOException;
    
    /** 关闭连接 */
    public void close();
    
    /********************************************************************/
    //连接中的相关连的 id & listener
    /********************************************************************/
    
    /** 连接编号 */
    public String getId();
    
    /** 连接对应的监听器 */
    public HttpListener getListener();
    
    /** 获取远程地址 */
    public String getRemoteAddr();
    
    /** 获取远程端口 */
    public int getRemotePort();
}
